package com.dragon.repository.domain.dto;

import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.OperationLog;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OperationLogDTO {

    private static final long serialVersionUID = 1L;

    private Integer id;

    @ApiModelProperty(value = "模块名称")
    private String modelName;

    @ApiModelProperty(value = "操作名称")
    private String name;

    @ApiModelProperty(value = "类名")
    private String modelCode;

    @ApiModelProperty(value = "方法名")
    private String actionCode;

    @ApiModelProperty(value = "操作参数")
    private String arg;

    @ApiModelProperty(value = "路径地址")
    private String uri;

    @ApiModelProperty(value = "操作人")
    private Integer adminId;

    @ApiModelProperty(value = "操作ip地址")
    private String ipAddress;

    @ApiModelProperty(value = "操作人")
    private String username;

    @ApiModelProperty(value = "操作时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date operationTime;


    public OperationLogDTO() {}

    public OperationLogDTO(OperationLog entity) {
        BeanUtils.copyProperties(entity,this);
    }

    public static OperationLogDTO convert(OperationLog entity) {
        return new OperationLogDTO(entity);
    }

    public static List<OperationLogDTO> convertList(List<OperationLog> list) {
        List<OperationLogDTO> resultList = new ArrayList<>();
        for (OperationLog entity : list) {
            resultList.add(new OperationLogDTO(entity));
        }
        return resultList;
    }}
